package drukarnia.controller;

import org.hibernate.Query;
import org.hibernate.Session;

import drukarnia.model.SizeInM2Tmp;
import drukarnia.util.HibernateUtil;

public class SizeInM2Manager extends HibernateUtil{
	
	public SizeInM2Tmp save(double sizeInM2, String fileName){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		SizeInM2Tmp size = new SizeInM2Tmp();
		size.setValue(sizeInM2);
		size.setName(fileName);
		session.save(size);
		session.getTransaction().commit();
		return size;
		
	}
	
	public void deleteAll(String fileName){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		Query q = session.createQuery("delete from SizeInM2Tmp where name='" + fileName + "'");
		q.executeUpdate();
		
		session.getTransaction().commit();
		
	}
}
